﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Data.Odbc;
using System.Data;
using EzDesk.DevHelper.DebugLibrary.Model;

namespace EzDesk.DevHelper.DebugLibrary
{

    public class EzDeskAttendanceInitial :EzDeskInitial, IEzDeskInitial
    {
        private Dictionary<string, Guid> UserIdDictionary = new Dictionary<string, Guid>();
        private Guid GetUserIdByUserName(string userName)
        {
            Guid userId = Guid.Empty;
            if (UserIdDictionary.Keys.Contains(userName))
            {
                userId = UserIdDictionary[userName];
            }
            else
            {
                using (EzDeskDataContext db = new EzDeskDataContext())
                {
                    var user = (from u in db.UserProfileSets
                                where u.UserCode == userName
                                select u).FirstOrDefault();

                    if (user == null)
                    {
                        Debug.WriteLine(userName + ": 没找到。");
                    }
                    else
                    {
                        userId = user.Id;
                        UserIdDictionary[userName] = userId;
                    }
                }
            }
            return userId;
        }

        public void Initialize()
        {
            Debug.WriteLine("开始配置考勤系统测试环境...");

            //添加App
            //添加考勤App
            Guid attendanceAppId = Guid.NewGuid();

            Dictionary<string, string> domains = new Dictionary<string, string>()
            {
                {"GenericMobile", "localhost:4902"},
                {"DesktopClient", "localhost:5902"},
            };



            //清除签到信息
            CleanUpAttendanceInfo();

            //清除法定假日信息
            CleanUpLegalHolidays();

            //添加法定节假日
            AddLegalHolidaysFor2009();

            //添加历史考勤数据
            ImportAttendanceDataUntil200911();

            //生成模拟考勤记录
            GenerateSimAttendanceRecords();

            // 清除假期数据
            CleanUpLeaveInfos();

            //导入假期数据
            ImportLeaveDataUntil200911();



            //添加考勤使用的分组
            //被考勤的人员组
            // 方案部 所有成员参与考勤

            //接受考勤报告的人员组


        }

        private static void CleanUpAttendanceInfo()
        {
            //清除所有签到信息
            using (EzDeskAttendanceDataContext attDb = new EzDeskAttendanceDataContext())
            {
                attDb.AttendanceInfoSets.DeleteAllOnSubmit(attDb.AttendanceInfoSets);
                attDb.SubmitChanges();
            }
            Debug.WriteLine("所有签到信息已经清除！");
        }



        private void ImportLeaveDataUntil200911()
        {            

            Debug.WriteLine("开始导入假期数据");
            using (EzDeskAttendanceDataContext attDb = new EzDeskAttendanceDataContext())
            {
                string connStr = @"Driver={Microsoft Access Driver (*.mdb)};Dbq=leave.mdb";
                using (OdbcConnection conn = new OdbcConnection(connStr))
                {
                    //导入请假类型
                    conn.Open();
                    string sqlStr = "SELECT * FROM scheduletype";
                    OdbcCommand cmd = new OdbcCommand(sqlStr, conn);
                    OdbcDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    while (dr.Read())
                    {
                        string typeName = dr["scheduletype"] as string;
                        string remark = dr["remark"] as string;
                        bool isWork = false;
                        if (typeName == "出差" || typeName == "外出")
                        {
                            isWork = true;
                        }

                        attDb.LeaveTypeSets.InsertOnSubmit(new LeaveTypeSet()
                        {
                            Id = Guid.NewGuid(),
                            LeaveTypeName = typeName,
                            Remark = remark,
                            IsForWork = isWork,
                        }
                        );
                    }

                    attDb.SubmitChanges();
                    Debug.WriteLine("请假类型信息写入完毕。");


                    Debug.WriteLine("开始导入历史请假信息。");
                    conn.Close();

                    conn.Open();
                    sqlStr = "SELECT * FROM timeschedule";
                    cmd = new OdbcCommand(sqlStr, conn);
                    dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    while (dr.Read())
                    {
                        string userName = dr["username"] as string;
                        string name = dr["name"] as string;

                        Guid userId;
                        userId = GetUserIdByUserName(userName);
                        if (userId == Guid.Empty) continue;

                        string leaveTypeName = dr["scheduletype"] as string;
                        var leaveType = (from l in attDb.LeaveTypeSets
                                         where l.LeaveTypeName == leaveTypeName
                                         select l).FirstOrDefault();
                        if (leaveType == null)
                        {
                            Debug.WriteLine("[验证假期类型] " + leaveType.LeaveTypeName + " 没找到");
                            continue;
                        }


                        DateTime leaveTime = (DateTime)dr["leaveday"];
                        DateTime comebackTime = (DateTime)dr["comebackday"];
                        string description = dr["purpose"] as string;

                        string auditName = dr["auditing_user"] as string;
                        string auditNote = dr["auditing_explain"] as string;
                        int auditing = (int)dr["auditing"];

                        Guid auditUserId;
                        using (EzDeskDataContext db = new EzDeskDataContext())
                        {
                            var user = (from u in db.UserProfileSets
                                        where u.Name == auditName
                                        select u).FirstOrDefault();
                            if (user == null)
                            {
                                Debug.Write("[验证AuditUser] " + auditName + " 没找到");
                                continue;
                            }
                            auditUserId = user.Id;
                        }

                        attDb.LeaveInfoSets.InsertOnSubmit(
                            new LeaveInfoSet()
                            {
                                Id = Guid.NewGuid(),
                                UserId = userId,
                                Description = description,
                                LeaveTypeId = leaveType.Id,
                                StartTime = leaveTime,
                                EndTime = comebackTime,
                                AuditUserId = auditUserId,
                                AuditNote = auditNote,
                                IsAudited = auditing == 1,
                                CreateOn = leaveTime,
                                IsAgreed = auditing == 1,
                                AuditTime = DateTime.Now
                            }
                            );
                    }
                    attDb.SubmitChanges();

                    Debug.WriteLine("历史请假信息导入完成。。");
                }
            }
        }

        private static void CleanUpLeaveInfos()
        {
            using (EzDeskAttendanceDataContext attDb = new EzDeskAttendanceDataContext())
            {
                Debug.WriteLine("清除请假数据");
                attDb.LeaveInfoSets.DeleteAllOnSubmit(attDb.LeaveInfoSets);
                attDb.SubmitChanges();
                Debug.WriteLine("请假信息已经清除");

                Debug.WriteLine("清除假期类型");
                attDb.LeaveTypeSets.DeleteAllOnSubmit(attDb.LeaveTypeSets);
                attDb.SubmitChanges();
                Debug.WriteLine("请假类型已清除。");

                Debug.WriteLine("清除轮休数据");
                attDb.ExtraShiftSets.DeleteAllOnSubmit(attDb.ExtraShiftSets);
                attDb.SubmitChanges();
                Debug.WriteLine("轮休数据已清除。");

                
            }
        }

        private void ImportAttendanceDataUntil200911()
        {
            Debug.WriteLine("开始添加历史考勤信息");
            using (EzDeskAttendanceDataContext attDb = new EzDeskAttendanceDataContext())
            {
                //从现有数据库中导入截止2009年11月的考勤数据
                // 打开 mdb 数据库
                string connStr = @"Driver={Microsoft Access Driver (*.mdb)};Dbq=kq2011.mdb";
                using (OdbcConnection conn = new OdbcConnection(connStr))
                {
                    conn.Open();
                    for (int i = 1; i <= 11; i++)
                    {
                        string sqlStr = "SELECT * FROM month" + i.ToString();
                        OdbcCommand cmd = new OdbcCommand(sqlStr, conn);
                        OdbcDataReader dr = cmd.ExecuteReader();
                        while (dr.Read())
                        {
                            string userName = dr["username"] as string;
                            string name = dr["name"] as string;

                            Guid userId;
                            userId = GetUserIdByUserName(userName);
                            if (userId == Guid.Empty) continue;

                            DateTime day = (DateTime)dr["day"];
                            int AttendanceTypeValue = 0;
                            DateTime actionTime = DateTime.Today;

                            DateTime comeDate = (DateTime)dr["comedate"];
                            if ((int)comeDate.TimeOfDay.TotalMinutes != 0)
                            {
                                AttendanceTypeValue = 0;
                                actionTime = new DateTime(
                                    day.Year,
                                    day.Month,
                                    day.Day,
                                    comeDate.Hour,
                                    comeDate.Minute,
                                    comeDate.Second
                                    );
                            }

                            DateTime leaveDate = (DateTime)dr["leavedate"];
                            if ((int)leaveDate.TimeOfDay.TotalMinutes != 0)
                            {
                                AttendanceTypeValue = 1;
                                actionTime = new DateTime(
                                    day.Year,
                                    day.Month,
                                    day.Day,
                                    leaveDate.Hour,
                                    leaveDate.Minute,
                                    leaveDate.Second
                                    );
                            }

                            string explain = dr["explain1"] as string;

                            attDb.AttendanceInfoSets.InsertOnSubmit(
                                new AttendanceInfoSet()
                                {
                                    Id = Guid.NewGuid(),
                                    UserId = userId,
                                    AttendanceTypeValue = AttendanceTypeValue,
                                    ActionTime = actionTime,
                                    Date = actionTime.Date,
                                    Explanation = explain,
                                    IsAbnormalAttendance = false,
                                }
                            );
                            attDb.SubmitChanges();
                        }
                       
                    }
                }
            }
        }

        private static void AddLegalHolidaysFor2009()
        {


            using (EzDeskAttendanceDataContext attDb = new EzDeskAttendanceDataContext())
            {
                //添加 2009 年法定假日条目
                attDb.LegalHolidaySets.InsertAllOnSubmit(
                    new List<LegalHolidaySet>(){
                        new LegalHolidaySet()
                        {
                            Id = Guid.NewGuid(),
                            StartDate = new DateTime(2009, 1, 1),
                            EndDate = new DateTime(2009, 1, 4),
                            HolidayName = "元旦节",
                            Year = 2009,
                        },
                        new LegalHolidaySet()
                        {
                            Id = Guid.NewGuid(),
                            StartDate = new DateTime(2009, 1, 25),
                            EndDate = new DateTime(2009, 1,31),
                            HolidayName = "春节",
                            Year = 2009,
                        },
                        new LegalHolidaySet()
                        {
                            Id = Guid.NewGuid(),
                            StartDate = new DateTime(2009, 4, 4),
                            EndDate = new DateTime(2009, 4, 6),
                            HolidayName = "清明节",
                            Year = 2009,
                        },
                        new LegalHolidaySet()
                        {
                            Id = Guid.NewGuid(),
                            StartDate = new DateTime(2009, 5, 1),
                            EndDate = new DateTime(2009, 5, 3),
                            HolidayName = "劳动节",
                            Year = 2009,
                        },
                        new LegalHolidaySet()
                        {
                            Id = Guid.NewGuid(),
                            StartDate = new DateTime(2009, 5, 28),
                            EndDate = new DateTime(2009, 5, 30),
                            HolidayName = "端午节",
                            Year = 2009,
                        },
                        new LegalHolidaySet()
                        {
                            Id = Guid.NewGuid(),
                            StartDate = new DateTime(2009, 10,1),
                            EndDate = new DateTime(2009,10,8),
                            HolidayName = "国庆节、中秋节",
                            Year = 2009,
                        },
                    }
                    );

                // 添加2009年调休假期
                attDb.ExtraShiftSets.InsertAllOnSubmit(
                    new List<ExtraShiftSet>()
                    {
                        new ExtraShiftSet()
                        {
                            Id = Guid.NewGuid(),
                            StartDate = new DateTime(2009, 1, 24),
                            EndDate = new DateTime(2009, 1, 24),
                            ShiftName = "春节调假",
                            IsNeedWork = true,
                        },
                        new ExtraShiftSet()
                        {
                            Id = Guid.NewGuid(),
                            StartDate = new DateTime(2009, 2, 1),
                            EndDate = new DateTime(2009, 2, 1),
                            ShiftName = "春节调假",
                            IsNeedWork = true,
                        },
                        new ExtraShiftSet()
                        {
                            Id = Guid.NewGuid(),
                            StartDate = new DateTime(2009, 10, 9),
                            EndDate = new DateTime(2009, 10, 12),
                            ShiftName = "集体年假",
                            IsNeedWork = false,
                        },
                    }
                    );

                attDb.SubmitChanges();
                Debug.WriteLine("2009年法定假日和调休添加完毕");


            }
        }

        private static void CleanUpLegalHolidays()
        {
            Debug.WriteLine("清除法定假日记录");


            using (EzDeskAttendanceDataContext attDb = new EzDeskAttendanceDataContext())
            {
                attDb.LegalHolidaySets.DeleteAllOnSubmit(attDb.LegalHolidaySets);
                attDb.SubmitChanges();
            }

            Debug.WriteLine("清除法定假日记录完成");
        }

        private static void GenerateSimAttendanceRecords()
        {

            //加入一些模拟考勤信息

            // 12.10 加班到晚上10点后 早上迟到 下午加班

            using (EzDeskAttendanceDataContext attDb = new EzDeskAttendanceDataContext())
            {
                // 12.8 加班到晚上10点后_早上正常_下午正常
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 8),
                        ActionTime = new DateTime(2009, 12, 8, 9, 1, 30),
                        AttendanceTypeValue = 0,
                        ////IsExtraWork = false,
                    }
                    );
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 8),
                        ActionTime = new DateTime(2009, 12, 8, 23, 20, 20),
                        AttendanceTypeValue = 1,
                        ////IsExtraWork = false,
                    }
                    );

                // 12.9 前一天晚上加班到10点后_早上迟到_下午正常
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 9),
                        ActionTime = new DateTime(2009, 12, 9, 10, 32, 30),
                        AttendanceTypeValue = 0,
                        //IsExtraWork = false,
                    }
                    );
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 9),
                        ActionTime = new DateTime(2009, 12, 9, 18, 20, 20),
                        AttendanceTypeValue = 1,
                        ////IsExtraWork = false,
                    }
                    );

                // 12.10 加班到晚上10点后_早上迟到_下午加班
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 10),
                        ActionTime = new DateTime(2009, 12, 10, 9, 6, 30),
                        AttendanceTypeValue = 0,
                        ////IsExtraWork = false,
                    }
                    );
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 10),
                        ActionTime = new DateTime(2009, 12, 10, 23, 20, 20),
                        AttendanceTypeValue = 1,
                        //IsExtraWork = false,
                    }
                    );

                // 12.11 前一天加班到晚上10点后 早上晚半小时到 下午加班
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 11),
                        ActionTime = new DateTime(2009, 12, 11, 9, 40, 30),
                        AttendanceTypeValue = 0,
                        //IsExtraWork = false,
                    }
                    );
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 11),
                        ActionTime = new DateTime(2009, 12, 11, 23, 20, 20),
                        AttendanceTypeValue = 1,
                        //IsExtraWork = false,
                    }
                    );

                // 12.12 周六加班_前一天加班到10点后 早上迟到 下午未考勤
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 12),
                        ActionTime = new DateTime(2009, 12, 12, 10, 29, 30),
                        AttendanceTypeValue = 0,
                        //IsExtraWork = false,
                    }
                    );
                //attDb.AttendanceInfoSets.InsertOnSubmit(
                //    new AttendanceInfoSet()
                //    {
                //        Id = Guid.NewGuid(),
                //        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                //        Date = new DateTime(2009, 12, 12),
                //        ActionTime = null,
                //        AttendanceTypeValue = 1,
                //        //IsExtraWork = false,
                //    }
                //    );

                // 12.13 周末加班 早上正常考勤 下午正常考勤
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 13),
                        ActionTime = new DateTime(2009, 12, 13, 10, 29, 30),
                        AttendanceTypeValue = 0,
                        //IsExtraWork = false,
                    }
                    );
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 13),
                        ActionTime = new DateTime(2009, 12, 13, 21, 2, 30),
                        AttendanceTypeValue = 1,
                        //IsExtraWork = false,
                    }
                    );

                // 12.14 一天未考勤，早上未考勤，下午未考勤
                //attDb.AttendanceInfoSets.InsertOnSubmit(
                //    new AttendanceInfoSet()
                //    {
                //        Id = Guid.NewGuid(),
                //        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                //        Date = new DateTime(2009, 12, 14),
                //        ActionTime = null,
                //        AttendanceTypeValue = 0,
                //        //IsExtraWork = false,
                //    }
                //    );
                //attDb.AttendanceInfoSets.InsertOnSubmit(
                //    new AttendanceInfoSet()
                //    {
                //        Id = Guid.NewGuid(),
                //        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                //        Date = new DateTime(2009, 12, 14),
                //        ActionTime = null,
                //        AttendanceTypeValue = 1,
                //        //IsExtraWork = false,
                //    }
                //    );

                // 12.15早上，早上迟到，下午未考勤
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 15),
                        ActionTime = new DateTime(2009, 12, 15, 8, 21, 20),
                        AttendanceTypeValue = 0,
                        //IsExtraWork = false,
                    }
                    );
                //attDb.AttendanceInfoSets.InsertOnSubmit(
                //    new AttendanceInfoSet()
                //    {
                //        Id = Guid.NewGuid(),
                //        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                //        Date = new DateTime(2009, 12, 15),
                //        ActionTime = null,
                //        AttendanceTypeValue = 1,
                //        //IsExtraWork = false,
                //    }
                //    );

                // 12.16早上，早上未考勤，下午正常下班
                //attDb.AttendanceInfoSets.InsertOnSubmit(
                //    new AttendanceInfoSet()
                //    {
                //        Id = Guid.NewGuid(),
                //        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                //        Date = new DateTime(2009, 12, 16),
                //        ActionTime = null,
                //        AttendanceTypeValue = 0,
                //        //IsExtraWork = false,
                //    }
                //    );
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 16),
                        ActionTime = new DateTime(2009, 12, 16, 18, 21, 20),
                        AttendanceTypeValue = 1,
                        //IsExtraWork = false,
                    }
                    );



                // 12.17早上，上班迟到，下午早退
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 17),
                        ActionTime = new DateTime(2009, 12, 17, 10, 25, 20),
                        AttendanceTypeValue = 0,
                        //IsExtraWork = false,
                    }
                    );
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 17),
                        ActionTime = new DateTime(2009, 12, 17, 16, 21, 20),
                        AttendanceTypeValue = 1,
                        //IsExtraWork = false,
                    }
                    );


                // 12.18早上 正常上班, 下午早退
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 18),
                        ActionTime = new DateTime(2009, 12, 18, 8, 40, 20),
                        AttendanceTypeValue = 0,
                        //IsExtraWork = false,
                    }
                    );
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 18),
                        ActionTime = new DateTime(2009, 12, 18, 17, 45, 20),
                        AttendanceTypeValue = 1,
                        //IsExtraWork = false,
                    }
                    );



                // 12.21 早上迟到，下午正常下班
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 21),
                        ActionTime = new DateTime(2009, 12, 21, 9, 8, 20),
                        AttendanceTypeValue = 0,
                        //IsExtraWork = false,
                    }
                    );
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 21),
                        ActionTime = new DateTime(2009, 12, 21, 18, 3, 20),
                        AttendanceTypeValue = 1,
                        //IsExtraWork = false,
                    }
                    );

                // 12.22早上 正常上班, 下午正常下班，上班时间在缓冲时间内
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 22),
                        ActionTime = new DateTime(2009, 12, 22, 9, 3, 20),
                        AttendanceTypeValue = 0,
                        //IsExtraWork = false,
                    }
                    );
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 22),
                        ActionTime = new DateTime(2009, 12, 22, 18, 2, 20),
                        AttendanceTypeValue = 1,
                        //IsExtraWork = false,
                    }
                    );

                // 12.23早上 正常上班, 下午正常下班
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 23),
                        ActionTime = new DateTime(2009, 12, 23, 8, 40, 20),
                        AttendanceTypeValue = 0,
                        //IsExtraWork = false,
                    }
                    );
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 12, 23),
                        ActionTime = new DateTime(2009, 12, 23, 18, 3, 20),
                        AttendanceTypeValue = 1,
                        //IsExtraWork = false,
                    }
                    );



                #region [ 今日考勤测试数据 ]
                // 添加3个测试员工的今日考勤记录
                // 上午迟到
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = DateTime.Today,
                        ActionTime = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day , 9, 40, 20),
                        AttendanceTypeValue = 0,
                        //IsExtraWork = false,
                    }
                );
                // 上午正常上班
                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = DateTime.Today,
                        ActionTime = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 8, 50, 20),
                        AttendanceTypeValue = 0,
                        //IsExtraWork = false,
                    }
                );
                //// 未到
                //attDb.AttendanceInfoSets.InsertOnSubmit(
                //    new AttendanceInfoSet()
                //    {
                //        Id = Guid.NewGuid(),
                //        UserId = new Guid("877c3323-17a7-42d1-9d75-402ffc894e63"),
                //        Day = DateTime.Today,
                //        ActionTime = null,
                //        AttendanceTypeValue = 0,
                //        //IsExtraWork = false,
                //    }
                //);


                #endregion

                #region [ 通宵加班测试数据 ]
                // 2010.3.1 申请通宵加班 加班到3.2凌晨 打卡下班 第二天正常打卡

                //attDb.ez_Person_ExtraWorks.InsertOnSubmit(
                //    new ez_Person_ExtraWork()
                //    {
                //        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                //        Day = new DateTime(2010, 3, 1),
                //    }
                //    );

                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2010, 3, 1),
                        ActionTime = new DateTime(2009, 3, 1, 8, 40, 20),
                        AttendanceTypeValue = 0,
                        //IsExtraWork = false,
                    }
                    );


                    attDb.AttendanceInfoSets.InsertOnSubmit(
                        new AttendanceInfoSet()
                        {
                            Id = Guid.NewGuid(),
                            UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                            Date = new DateTime(2009, 3, 1),
                            ActionTime = new DateTime(2009, 3, 1, 23, 59, 00),
                            AttendanceTypeValue = 1,
                            //IsExtraWork = false,
                        }
                        );
                    attDb.AttendanceInfoSets.InsertOnSubmit(
                        new AttendanceInfoSet()
                        {
                            Id = Guid.NewGuid(),
                            UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                            Date = new DateTime(2010, 3, 2),
                            ActionTime = new DateTime(2009, 3, 2, 0, 0, 0),
                            AttendanceTypeValue = 0,
                            //IsExtraWork = true,
                        }
                        );

                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 3, 2),
                        ActionTime = new DateTime(2009, 3, 2, 3, 0, 0),
                        AttendanceTypeValue = 1,
                        //IsExtraWork = true,
                    }
                    );

                            attDb.AttendanceInfoSets.InsertOnSubmit(
                new AttendanceInfoSet()
                {
                    Id = Guid.NewGuid(),
                    UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                    Date = new DateTime(2010, 3, 2),
                    ActionTime = new DateTime(2009, 3, 2, 8, 0, 0),
                    AttendanceTypeValue = 0,
                    //IsExtraWork = true,
                }
                );

                attDb.AttendanceInfoSets.InsertOnSubmit(
                    new AttendanceInfoSet()
                    {
                        Id = Guid.NewGuid(),
                        UserId = new Guid("0c9d7c0c-04a5-4ae2-97a1-d7bbc38f5c66"),
                        Date = new DateTime(2009, 3, 2),
                        ActionTime = new DateTime(2009, 3, 2, 19, 00, 00),
                        AttendanceTypeValue = 1,
                        //IsExtraWork = true,
                    }
                    );

                // 2010.3.3 未申请通宵加班 加班到3.4凌晨

                #endregion

                attDb.SubmitChanges();
            }

            Debug.WriteLine("添加模拟考勤数据完成");
        }

        #region IEzDeskInitial Members


        public void AddInitializeModule(IEzDeskInitial EzDeskMessageInitial)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
